package com.ly.java.annotation5;

public class ReflectAnnotationTest {
    public static void main(String[] args) throws Exception {
        Class<?> myAnnotationTest = Class.forName("com.ly.java.annotation5.MyAnnotationTest");
        // 判断类上面是否有@MyAnnotation
        System.out.println(myAnnotationTest.isAnnotationPresent(MyAnnotation.class));

        // 判断String类上是否存在注解
        Class<?> aClass = Class.forName("java.lang.String");
        System.out.println(aClass.isAnnotationPresent(MyAnnotation.class));

        // 获取类上的注解
        if (myAnnotationTest.isAnnotationPresent(MyAnnotation.class)) {
            MyAnnotation annotation = (MyAnnotation) myAnnotationTest.getAnnotation(MyAnnotation.class);
            System.out.println("类上面的注解对象" + annotation);
            // 获取注解对象的属性怎么办？
            System.out.println(annotation.value());

        }
    }
}
